﻿using RBAC.Repository;
using RBAC.Repository.RabbitInterfae;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.Domain;
using Traceability.Service.Interfae;

namespace Traceability.Service.Impl
{
    public class SlaughterService : ISlaughterService
    {
        private readonly ISlaughterRepository _slaughterRepository;
        public SlaughterService(ISlaughterRepository laughterRepository)
        {
            _slaughterRepository = laughterRepository;
        }
        /// <summary>
        /// 添加屠宰信息
        /// </summary>
        /// <param name="slaughter"></param>
        /// <returns></returns>
        public async Task<int> AddSlaughter(Slaughter slaughter)
        {
          return await _slaughterRepository.AddAsync(slaughter);
        }
        /// <summary>
        /// 显示屠宰信息
        /// </summary>
        /// <param name="bath"></param>
        /// <returns></returns>
        public async Task<List<Slaughter>> GetSlaughter(string bath)
        {
            var listobj = from a in await _slaughterRepository.GetAllAsync()

                          where !a.SlaughterDel && a.Batch == bath
                          select a;
            return listobj.ToList();
        }
        /// <summary>
        /// 反填屠宰信息
        /// </summary>
        /// <param name="bath"></param>
        /// <returns></returns>
        public async Task<List<Slaughter>> GetSlaughterBy(string bath)
        {
            var listobj = from a in await _slaughterRepository.GetAllAsync()

                          where !a.SlaughterDel && a.SBatch == bath
                          select a;
            return listobj.ToList();
        }
        /// <summary>
        /// 修改屠宰信息
        /// </summary>
        /// <param name="slaughter"></param>
        /// <returns></returns>
        public async Task<int> UpdateSlaughter(Slaughter slaughter)
        {
           return await _slaughterRepository.UpdateAsync(slaughter);
        }
    }
}
